#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 1e5 + 10;
int stk[N], tt;

signed main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		while (tt && stk[tt] >= x) tt--;
		cout << (tt ? stk[tt] : -1) << " ";
		stk[++tt] = x;
	}
	return 0;
}